#include "spiral_1.h"

extern int G_H,G_W;

SPIRAL_1::SPIRAL_1(QPoint start, bool left_orientation, SCENE *scene, QTimeLine *global_tl, CASH *cash):QGraphicsObject()
{

    shot = new SOUND_POWER(cash,"Res/Sound/Enemy/Enemy_8/shot.ogg",this);
    shot->Play_Now();

    point=40;

    this->setZValue(0.5);

    border = cash->cash_poly->value("Res/weapons/Spiral_1/Spiral.poly");
    im = cash->cash_pixmap->value("Res/weapons/Spiral_1/Spiral.png");

    anim_rocket = new QGraphicsItemAnimation();

    rocket_time_line = new QTimeLine(500);
    rocket_time_line->setEasingCurve(QEasingCurve::Type(1));
    rocket_time_line->setFrameRange(0,1);

    anim_rocket->setTimeLine(rocket_time_line);
    anim_rocket->setItem(this);
    anim_rocket->setPosAt(0,start);

    if(left_orientation)
        anim_rocket->setPosAt(1,QPoint( start.x()+G_W,start.y()) );
    else
        anim_rocket->setPosAt(1, QPoint( -300,start.y() ) );

    rocket_time_line->start();

    collisia_control = new COLLISIA_CONTROL(scene,((QGraphicsObject*)this),this,global_tl,cash,100);

    connect(collisia_control,SIGNAL(Collisia(QPointF,int)),this,SLOT(Damage_Detected(QPointF,int)));
    connect(rocket_time_line,SIGNAL(finished()),SLOT(deleteLater()));


}

QRectF SPIRAL_1::boundingRect() const
{

    return QRectF( QPointF(0,0),im->size() );

}

QPainterPath SPIRAL_1::shape() const
{

    return *border;

}

void SPIRAL_1::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
{

    painter->save();
    painter->drawPixmap( 0,0,*im);
    painter->restore();

}

SPIRAL_1::~SPIRAL_1()
{
    shot->Stop();
}

int SPIRAL_1::type() const
{

    return point;

}

void SPIRAL_1::Damage_Detected(QPointF a, int d)
{

    a = QPointF();
    point-=d;

    if(point<=0) {
        shot->Stop();
        this->scene()->removeItem(this);
    }

}




